<%@ include file="common.jspf"%>
<%@ include file="header.jspf"%>

<div class="container">
	<blockquote>
		<h3>English Edit</h3>
	</blockquote>
	<form id="formEdit" role="form">
		<input id="no" name="no" type="hidden" value="${param.no}"/>
		<div class="form-group">
			<label for="category">Category</label> 
			<select id="categorySelect" name="category" class="form-control"><option></option></select>
		</div>
		<div class="form-group">
			<label for="title">Title</label> 
			<input id="title" name="title" type="text" class="form-control"/>
		</div>
		<div class="form-group">
			<label for="content">Content</label> 
			<textarea id="content" name="content" class="form-control" rows="10"></textarea>
		</div>
		<div class="form-group">
			<label for="url">URL</label> 
			<input id="url" name="url" type="url" class="form-control"/>
		</div>
		<div class="form-group pull-right">
			<button id="btnSubmit" type="button" class="btn btn-default">
				<span class="glyphicon glyphicon-save"></span> Submit
			</button>
			<button id="btnCancel" type="button" class="btn btn-default">
				<span class="glyphicon glyphicon-step-backward"></span> Cancel
			</button>
		</div>
	</form>
</div>

<script>
	function getMode() {
	}

	$(function() {
		initEvents();
		initData();
	});
	
	function initData() {
		$.getJSON('${urlCategoryOptions}', function(data) {
			$.each(data, function(idx, val) {
				$('<option/>').text(val).appendTo($('#categorySelect'));
			});
		});
		
		if (!'${param.no}') {
			return;
		}
		
		$.getJSON('${urlFind}', {no: '${param.no}'}, function(data) {
			$('#categorySelect').val(data.category);
			$('#category').val(data.category);
			$('#title').val(data.title);
			$('#content').val(data.content);
			$('#url').val(data.url);
		});
	}
	
	function initEvents() {
		$('#btnSubmit').click(function() {
			if ('${param.no}') {
				modify(toJson('#formEdit'));	
			} else {
				create(toJson('#formEdit'));
			}
		});
		$('#btnCancel').click(back);
	}
</script>

<%@ include file="footer.jspf"%>